home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / InsertUrl.cpp < prev    next >
C/C++ Source or Header  |  2002-04-14  |  6KB  |  233 lines

  1. // InsertUrl.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. extern "C" {
  7.   #include "htsglobal.h"
  8.   #include "htslib.h"
  9. }
  10. #include "winsock.h"
  11.  
  12. #include "Shell.h"
  13. #include "InsertUrl.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. extern HICON httrack_icon;
  22.  
  23. // Helper
  24. extern LaunchHelp* HtsHelper;
  25.  
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CInsertUrl dialog
  29.  
  30.  
  31. CInsertUrl::CInsertUrl(CWnd* pParent /*=NULL*/)
  32.     : CDialog(CInsertUrl::IDD, pParent)
  33. {
  34.     //{{AFX_DATA_INIT(CInsertUrl)
  35.     m_urllogin = _T("");
  36.     m_urlpass = _T("");
  37.     m_urladr = _T("");
  38.     //}}AFX_DATA_INIT
  39. }
  40.  
  41.  
  42. void CInsertUrl::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CInsertUrl)
  46.     DDX_Text(pDX, IDC_urllogin, m_urllogin);
  47.     DDX_Text(pDX, IDC_urlpass, m_urlpass);
  48.     DDX_Text(pDX, IDC_urladr, m_urladr);
  49.     //}}AFX_DATA_MAP
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(CInsertUrl, CDialog)
  54.     //{{AFX_MSG_MAP(CInsertUrl)
  55.     ON_BN_CLICKED(ID_capt, Oncapt)
  56.     //}}AFX_MSG_MAP
  57.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  58.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  59.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  60.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CInsertUrl message handlers
  65.  
  66. BOOL CInsertUrl::OnInitDialog() 
  67. {
  68.     CDialog::OnInitDialog();
  69.   SetIcon(httrack_icon,false);
  70.   SetIcon(httrack_icon,true);
  71.   EnableToolTips(true);     // TOOL TIPS
  72.   SetForegroundWindow();   // yop en premier plan!
  73.     
  74.   if (LANG_T(-1)) {    // Patcher en franτais
  75.     SetWindowText( LANG(LANG_T1));
  76.     SetDlgItemText(IDC_STATIC_adr,LANG(LANG_T2));
  77.     SetDlgItemText(IDC_STATIC_auth,LANG(LANG_T4));
  78.     SetDlgItemText(IDC_STATIC_login,LANG(LANG_T5));
  79.     SetDlgItemText(IDC_STATIC_pass,LANG(LANG_T6));
  80.     SetDlgItemText(IDC_STATIC_capt,LANG(LANG_T7));
  81.     SetDlgItemText(ID_capt,LANG(LANG_T8));
  82.     SetDlgItemText(IDOK,LANG(LANG_OK));
  83.     SetDlgItemText(IDCANCEL,LANG(LANG_CANCEL));
  84.   }
  85.  
  86.     return TRUE;  // return TRUE unless you set the focus to a control
  87.                   // EXCEPTION: OCX Property Pages should return FALSE
  88. }
  89.  
  90.  
  91. // ------------------------------------------------------------
  92. // TOOL TIPS
  93. //
  94. // ajouter dans le .cpp:
  95. // remplacer les deux Wid1:: par le nom de la classe::
  96. // dans la message map, ajouter
  97. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  98. // dans initdialog ajouter
  99. // EnableToolTips(true);     // TOOL TIPS
  100. //
  101. // ajouter dans le .h:
  102. // char* GetTip(int id);
  103. // et en generated message map
  104. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  105. BOOL CInsertUrl::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  106. {
  107.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  108.   UINT nID =pNMHDR->idFrom;
  109.   if (pTTT->uFlags & TTF_IDISHWND)
  110.   {
  111.     // idFrom is actually the HWND of the tool
  112.     nID = ::GetDlgCtrlID((HWND)nID);
  113.     if(nID)
  114.     {
  115.       char* st=GetTip(nID);
  116.       if (st != "") {
  117.         pTTT->lpszText = st;
  118.         pTTT->hinst = AfxGetResourceHandle();
  119.         return(TRUE);
  120.       }
  121.     }
  122.   }
  123.   return(FALSE);
  124. }
  125. char* CInsertUrl::GetTip(int ID)
  126. {
  127.   switch(ID) {
  128.     case IDC_urladr:    return LANG(LANG_T10); break;
  129.     case IDC_urllogin:  return LANG(LANG_T12); break;
  130.     case IDC_urlpass:   return LANG(LANG_T13); break;
  131.     case ID_capt:       return LANG(LANG_T14); break;
  132.     case IDOK:           return LANG(LANG_TIPOK); break;      
  133.     case IDCANCEL:       return LANG(LANG_TIPCANCEL); break;
  134.     //case : return ""; break;
  135.   }
  136.   return "";
  137. }
  138. // TOOL TIPS
  139. // ------------------------------------------------------------
  140.  
  141. // Appel aide
  142. BOOL CInsertUrl::OnHelpInfo2() {
  143.   return OnHelpInfo(NULL);
  144. }
  145.  
  146. BOOL CInsertUrl::OnHelpInfo(HELPINFO* dummy) 
  147. {
  148.   HtsHelper->Help();
  149.   return true;
  150. }
  151.  
  152. // Ne fait pas partie de la classe
  153. UINT RunBackCatchServer( LPVOID pP ) {
  154.   CInsertUrl* _this=(CInsertUrl*) pP;
  155.   //
  156.   char url[HTS_URLMAXSIZE*2]; url[0]='\0';
  157.   char method[32]; method[0]='\0';
  158.   char data[32768]; data[0]='\0';
  159.   if (catch_url(_this->soc,url,method,data)) {
  160.     if (_this->m_hWnd) {
  161.       char dest[HTS_URLMAXSIZE*2];
  162.       int i=0;
  163.       strcpy(dest,_this->dest_path);
  164.       {
  165.         char* a;
  166.         while(a=strchr(dest,'\\')) *a='/';
  167.         structcheck(dest);
  168.       }
  169.       do {
  170.         sprintf(dest,"%s%s%d",_this->dest_path,"hts-post",i);
  171.         i++;
  172.       } while(fexist(dest));
  173.       {
  174.         FILE* fp=fopen(dest,"wb");
  175.         if (fp) {
  176.           fwrite(data,strlen(data),1,fp);
  177.           fclose(fp);
  178.         }
  179.       }
  180.       // former URL!
  181.       {
  182.         char finalurl[HTS_URLMAXSIZE*2];
  183.         escape_check_url(dest);
  184.         sprintf(finalurl,"%s"POSTTOK"file:%s",url,dest);
  185.         _this->SetDlgItemText(IDC_urladr,finalurl);
  186.       }
  187.     }
  188.   } else {
  189.     CString info;
  190.     info.Format("Error while capturing URL\n(from %s)",url);
  191.     AfxMessageBox(info);
  192.   }
  193. #ifdef _WIN32
  194.   closesocket(_this->soc);
  195. #else
  196.   close(_this->soc);
  197. #endif
  198.   // Quitter
  199.   if (_this->m_hWnd) {
  200.     if (_this->dial.m_hWnd) {
  201.       ::SendMessage(_this->dial.m_hWnd,WM_CLOSE,0,0);
  202.     }
  203.   }
  204.   //_this->dial.EndDialog(IDOK);
  205.   return 0;
  206. }
  207.  
  208. void CInsertUrl::Oncapt() 
  209. {
  210.   // Demander un port d'Θcoute
  211.   adr_prox[0]='\0';
  212.   port_prox=0;
  213.   soc=catch_url_init_std(&port_prox,adr_prox);
  214.   if (soc != INVALID_SOCKET) {
  215.     //
  216.     char s[8192];
  217.     sprintf(s,"Please TEMPORARILY set your browser's proxy preferences to:\r\n\r\nProxy's address:\r\n%s\r\nProxy's port:\r\n%d\r\n",adr_prox,port_prox);
  218.     //
  219.     dial.m_info=s;
  220.     // ECOUTER EN THREAD
  221.     AfxBeginThread(RunBackCatchServer,this);
  222.     // AFFICHER INFOS
  223.     {
  224.       CWaitCursor wait;      // Afficher curseur sablier
  225.       if (dial.DoModal() != IDOK) {
  226.       }
  227.     }
  228.     //
  229.   } else
  230.     AfxMessageBox("Error!..",MB_SYSTEMMODAL);
  231. }
  232.  
  233.